<!--写月报-->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>学生端提交日报页</title>
		<script src="../../script/mui.min.js"></script>
		<script src="../../script/jquery.min.js" type="text/javascript"></script>
		<script src="../../script/timecontrol.min.js"></script>
		<script src="../../script/common.js"></script>
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/timecontrol.min.css" />
		<!--<link rel="stylesheet" href="../../css/CFNetPP_Base.css">-->
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
	</head>
	<body>
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar">
			<a class="base_left_item" href="#" onclick="showAlert()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span>写日报</span>
			<a class="base_right_item base_hide_item" href="#"> </a>
		</div>
		<div class=" writeReport"style="margin-top: 65px">
			<div data-role="fieldcontain" class="timecontrol bgwhite" id="" >
				<span class="font16 base_dark_grey left_15">时间</span>
				<input type="text" id="time" class="timeipt right" />
			</div>
			<div class="bgwhite top_10">
				<p class="title titlepos">
					本日总结
				</p>
				<div class="textare_div">
					<textarea class="textarea_t bottom_10" id="summary"  placeholder='字数不得少于5个字'></textarea>
				</div>
			</div>
			<button id="sumbit_bt" type="button" class=" top_30 bottom_30  mui-btn btns mui-btn-block  " onclick="UploadData()" disabled="true">
				提交
			</button>
		</div>
		<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title">是否放弃在此页面操作？</strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
					<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/utils.js"></script>
	<script type="text/javascript" src="../../script/base64.min.js"></script>
	<script type="text/javascript">
		var summary = '';
		//空格回车判断
		var parten = /^\s*$/;
		var accesspageurl = window.location.pathname;
		var accesspagetitle = document.title;
		var pid="";
		apiready = function() {
			//			SendBehaviorTrajectoriesNotifi('0', '学生端提交日报', '089');
			SendBehaviorTrajectoriesNotifi1('0', '学生端提交日报', '089', api.pageParam.sourceurl, api.pageParam.sourcetitle, accesspageurl, accesspagetitle);
			judgePracticeType();
			prepareData();
			backKey();
		}
		//学生端获取实习计划状态（仅限学生端）
		function judgePracticeType() {
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid')
			};
			cfnetppPOST(urlPracticeType, param, true, function(data, status) {
				if (status == 'success') {
					//										alert(JSON.stringify(data));
					//1,成功，返回success
					if (data.status == 1) {
						var list = data.json;
						if (list != null && list != '') {
							sxtypes = parseInt(list.sxtypes);
							pid=list.id;
							//0：顶岗，1：认知，2:跟岗
							if (sxtypes != 1) {
								$('#sumbit_bt').unbind('click').addClass('mui-btn-warning').removeClass('btns').attr('disabled', false);
							}
						} else {
							ShowToast('你还未有实习计划，请等待老师分配');
						}
					} else if (data.status == -1) {
						ShowToast('你还未有实习计划，请等待老师分配');
					} else {
						ShowToast('你还未有实习计划，请等待老师分配');
					}
				}
			})
		}

		function UploadData() {
			//			SendBehaviorTrajectoriesNotifi('1', '学生端提交日报', '089');
			summary = $('#summary').val();
			var weeklytime = timeStampWithString($('#time').val());
			if (summary.length == 0 || parten.test(summary)) {
				ShowToast('提交信息不完整，请完善信息后再次提交');
			} else if (summary.length < 5) {
				ShowToast('字数不得小于5个字');
			} else if (summary.length > 5000) {
				ShowToast('字数不得大于5000个字');
			} else {
				showProgress();
				var params = {
					uid : $api.getStorage('cfnetppuid'),
					jid : $api.getStorage('cfnetppjid'),
					weeklytime : weeklytime,
					summary : Base64.encode(summary),
					pid:pid,
					message:'日报'
				};
				cfnetppPOST(urlTjdaily, params, false, function(data, status) {
				SendBusinessOperationsLogNotifi('学生端提交日报', '089', params, params, '', data, '学生端提交日报接口', '089-01')
					hideProgress();
					if (status == 'success') {
						//1,成功，返回success
						if (data.status == 1) {
							
							ShowToast('提交成功');
							sendNotifi();
							backClick();
							//2,您本月已提交过日报,返回has
						} else if (data.status == 2) {
							ShowToast('你今日已提交过日报!');
							//3,您处于未实习状态,返回job
						} else if (data.status == 3) {
							ShowToast('您处于未实习状态，暂不能提交日报!');
							//4,实习时间已经到期,返回end
						} else if (data.status == 4) {
							ShowToast('你本次实习已经结业啦，不用再提交了!');
							//5,你选择的提交时间不在实习期间,返回sxtime
						} else if (data.status == 5) {
							ShowToast('你选择的提交时间不在实习期间');
						} else {
							ShowToast('提交失败，请重试!');
						}
					} else {
						ShowToast('网络异常,请检查网络!');
					}
				});
			}
		}

		//检测手机返回键
		function backKey() {
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				showAlert();
			});
		}

		function showAlert() {
			summary = $('#summary').val();
			//对页面进行了数据处理
			if (summary.length > 0) {
				$('#offlineAlert').show();
			} else {
				backClick();
			}
		}

		function backClick() {
			//			SendBehaviorTrajectoriesNotifi('1', '学生端提交日报', '089');
			SendBehaviorTrajectoriesNotifi1('1', '学生端提交日报', '089', api.pageParam.sourceurl, api.pageParam.sourcetitle, accesspageurl, accesspagetitle);
			api.closeWin({
			});
		}

		function cleanCancel() {
			$('#offlineAlert').hide();
		}

		//确定
		function cleanConfirm() {
			$('#offlineAlert').hide();
			backClick();
		}

		//提交日报成功发送通知给日报列表
		function sendNotifi() {
			api.sendEvent({
				name : 'RefreshDaliyNotifi'
			});
		}

		function prepareData() {
			var currenttime = new currentTime();
			//当前时间   currenttime.currentDate当前日期 currenttime.currentTime当前时间  currenttime.currentDatetime当前日期时间
			var curr = currenttime.year;
			timeInit(curr);
			// 时间控件
			var currenttime = new currentTime();
			$("#time").val(currenttime.currentDate);
			$("#time").change(function() {
				var setDate = $("#time").val();
				var d = new Date(Date.parse(setDate.replace(/-/g, "/")));
				var curDate = new Date();
				if (d > curDate) {
					alert("请选择正确的日期！");
					$("#time").val(currenttime.currentDate)
				}
			});
		}

		function timeInit(curr) {
			// 如需修改类型 date是年月日 time是24小时时间 datetime是时期和时间
			$('#time').mobiscroll().date({
				dateFormat : 'yyyy-mm-dd',
				lang : 'zh',
				//				startDay : 1,//开始日期
				//				startMonth : 0, // 开始月份
				startYear : curr, //开始年份
				endYear : curr + 1//结束年份
			});
		}
	</script>
</html>